//
//  LKMyVideoCollectionViewController.m
//  YLHelper
//
//  Created by she1323 on 2018/5/10.
//  Copyright © 2018年 she1323. All rights reserved.
//

#import "LKMyVideoCollectionViewController.h"
#import "LKElearnCollectionViewCell.h"
#import "LKElearningAvPlayerViewController.h"
#import "LKVideoModel.h"
@interface LKMyVideoCollectionViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property(nonatomic,strong)UICollectionView *collectionView;
@property(nonatomic,strong)UICollectionViewFlowLayout *flowLayout;
@property(nonatomic,strong)NSMutableArray *dataListArray;
@end

@implementation LKMyVideoCollectionViewController

-(RACSubject *)pushSubject{
    if (!_pushSubject) {
        _pushSubject = [RACSubject subject];
    }
    return _pushSubject;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setcollectionView];
    [self getMyCollectionVideo];
    // Do any additional setup after loading the view.
}
/**
 设置collectionview
 */
-(void)setcollectionView{

    self.flowLayout = [[UICollectionViewFlowLayout alloc] init];
    self.flowLayout.itemSize = CGSizeMake((WIDTH - 45)/2, 175);
    self.flowLayout.minimumLineSpacing = 12;
    self.flowLayout.minimumInteritemSpacing = 9;
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - (NAVIGATION_BAR_HEIGHT + 45)) collectionViewLayout:self.flowLayout];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.collectionView];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    self.collectionView.emptyDataSetSource = self;
    self.collectionView.emptyDataSetDelegate = self;
    [self.collectionView registerNib:[UINib nibWithNibName:@"LKElearnCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"LKElearnCollectionViewCell"];
//    [self.collectionView reloadData];
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.dataListArray.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    LKElearnCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"LKElearnCollectionViewCell" forIndexPath:indexPath];
    cell.model = self.dataListArray[indexPath.row];
    return cell;
}
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(20, 16, 0, 16);
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    LKVideoModel *videoModel = self.dataListArray[indexPath.row];
    [self.pushSubject sendNext:videoModel];
    
//    [self.pushSubject sendCompleted];
    
}
-(void)getMyCollectionVideo{
    [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:myCollectVideoUrl header:[LKUserInforTool header] parameters:nil progress:^(NSProgress * _Nullable progress) {
        
    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
        NSArray *items = responseObject[@"result"];
        for (NSDictionary *dic in items) {
            LKVideoModel *videoModel = [LKVideoModel modelWithDictionary:dic];
            [self.dataListArray addObject:videoModel];
        }
        [self.collectionView reloadData];
    } failure:^(NSString * _Nullable errorMessage) {
        
    }];
}

-(NSMutableArray *)dataListArray{
    if (!_dataListArray) {
        _dataListArray = [[NSMutableArray alloc] init];
    }
    return _dataListArray;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
